home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / asmlib35.zip / STARTUP.ASM < prev    next >
Assembly Source File  |  1992-10-19  |  2KB  |  110 lines

  1. include    asm.inc
  2.  
  3. extrn    endprog:proc
  4. extrn    breaktrap:proc
  5. extrn    breakrelease:proc
  6. IFDEF    HEAP
  7. extrn    hinit:proc
  8. ENDIF
  9. extrn    mymain:proc
  10.  
  11. ; make LINK search through ASMLIB for external references
  12. ; so I don't have to specify ASMLIB on the command line
  13. IF codesize EQ 1
  14. IF datasize EQ 2
  15.     IFDEF    NOXT
  16.     includelib    286huge
  17.     ELSE
  18.     includelib    asmhuge
  19.     ENDIF
  20. ELSE
  21.     IFDEF    NOXT
  22.     includelib    286lib
  23.     ELSE
  24.     includelib    asmlib
  25.     ENDIF
  26. ENDIF
  27. ELSE
  28.     IFDEF    NOXT
  29.     includelib    286small
  30.     ELSE
  31.     includelib    asmsmall
  32.     ENDIF
  33. ENDIF
  34.  
  35. stacksize    equ    1024
  36.  
  37. .stack stacksize
  38.  
  39. .data
  40. public    pspseg
  41. pspseg        dw    ?        ; storage for PSP segment
  42.  
  43. IFDEF    HEAP
  44. ; make some space available for the local heap
  45. heapsize    equ    32767
  46. heapbuffer    db    heapsize dup(0)
  47. ENDIF
  48.  
  49. .code
  50. start:
  51. ; start by pointing DS to DGROUP
  52.     mov    dx,@data
  53.     mov    ds,dx
  54.     assume    ds:@data
  55.  
  56. ; adjust for MS-LINK bug that puts SS in wrong segment
  57. ; THIS ADJUSTMENT IS REQURIED BY SEVERAL ASMLIB SUBROUTINES
  58.     mov    ax,ss
  59.     sub    ax,dx            ; paragraph difference
  60.     mov    cl,4
  61.     shl    ax,cl            ; converted to bytes
  62.     add    sp,ax            ; fix SP for new SS
  63.     mov    ss,dx            ; assume ss:DGROUP
  64.  
  65. ; save PSP segment for DOS 2.xx
  66.     mov    pspseg,es
  67.  
  68. ; next, release memory beyond the end of the program
  69. ; The file ENDPROG.ASM has a definition for ZSEG, marking the
  70. ; end of the program's code, data and stack area.  I want to
  71. ; release memory beyond ZSEG so I can use DOS function 48h for
  72. ; memory allocation.
  73. ; When linking ENDPROG.OBJ with your other object files, be sure
  74. ; ENDPROG is at the end of your list of object files.  The new segment
  75. ; ZSEG surprises link, and it has little choice but to put ZSEG
  76. ; at the end of the program.
  77.     call    endprog            ; returns AX = last segment 
  78.  
  79.     mov    bx,es            ; first segment (ES = seg PSP)
  80.     sub    bx,ax
  81.     neg    bx            ; size of program in paragraphs
  82.     mov    ah,4Ah            ; resize memory block
  83.     int    21h
  84.  
  85. IFDEF    HEAP
  86. ; need to initialize the heap in order to work properly.  A common cause
  87. ; of bombed programs is failure to initilaize the heap.
  88.     lea    bx,heapbuffer
  89.     mov    ax,heapsize
  90.     call    hinit
  91. ENDIF
  92.  
  93. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  94. ; Ctrl+Alt+Del key combinations
  95.     call    breaktrap
  96.  
  97. ; call your main program here
  98.     call    mymain
  99.  
  100. exit:
  101. ; de-activate the Ctrl+Break trap
  102.     call    breakrelease
  103.  
  104. ; normal program exit
  105.     mov    ax,4C00h
  106.     int    21h
  107.  
  108. end    start
  109.     end
  110.